﻿using System.Threading;
using System.Collections;
namespace System.Web
{
    public partial class NetHttpApplication
    {
        internal class AsyncAppEventHandler
        {
            private ArrayList _beginHandlers = new ArrayList();
            private int _count = 0;
            private ArrayList _endHandlers = new ArrayList();
            private ArrayList _stateObjects = new ArrayList();

            internal AsyncAppEventHandler() { }

            internal void Add(BeginEventHandler beginHandler, EndEventHandler endHandler, object state)
            {
                _beginHandlers.Add(beginHandler);
                _endHandlers.Add(endHandler);
                _stateObjects.Add(state);
                _count++;
            }

            internal void CreateExecutionSteps(NetHttpApplication app, ArrayList steps)
            {
                for (int i = 0; i < _count; i++)
                    steps.Add(new AsyncEventExecutionStep(app, (BeginEventHandler)_beginHandlers[i], (EndEventHandler)_endHandlers[i], _stateObjects[i]));
            }

            internal void Reset()
            {
                _count = 0;
                _beginHandlers.Clear();
                _endHandlers.Clear();
                _stateObjects.Clear();
            }

            internal int Count
            {
                get { return _count; }
            }
        }
    }
}